<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
	#div1 {width: 100px; height: 100px;background: red; position: absolute; left: 0;top: 50px;}	
	#div2 {width: 1px; height: 300px; position: absolute; top: 0; left: 300px; background: black;}
	#div3 {width: 1px; height: 300px; position: absolute; top: 0; left: 100px; background: black;}
</style>
<script>
function startMove(iTarget)
{
	 var timer = null;
		var oDiv = document.getElementById('div1');
		
		clearInterval(timer);
		timer = setInterval(function(){
			  var speed =0;
			
					if(oDiv.offsetLeft>iTarget)
						{
								speed =-7;
						}
						else
						{
								speed =7;
						}
			if(Math.abs(oDiv.offsetLeft - iTarget)<=7)
				{
						oDiv.style.left =iTarget + 'px';
						clearInterval(timer);
				}
			else{
						oDiv.style.left=oDiv.offsetLeft + speed + 'px';
			}
				/*
			var speed = (iTarget - oDiv.offsetLeft)/7;
			
			speed =speed>0?Math.ceil(speed):Math.floor(speed);
		
			oDiv.style.left=oDiv.offsetLeft + speed + 'px';
			document.title =oDiv.offsetLeft + ',' + speed;
			if(speed==0)
				{
					clearInterval(timer);
				}
			*/
		},30);
}
</script>
</head>

<body>
<input type="button" value="to100" onClick="startMove(100)">
<input type="button" value="to300" onClick="startMove(300)">
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>
</body>
</html>
